package leetcode.rotateA;

public class RotateA {
	
	public static int maxRotateFunction(int[] a) {
		int i, ng = a.length, sum = 0, iteration = 0;
		
		for (i = 0; i < ng; i++) {
			sum += a[i];
			iteration += i * a[i];
		}
		
		int max = iteration;
		
		for ( i = ng - 1; i > 0; i-- ) {
			iteration = iteration + sum - ng * a[i];
			max = Math.max(max, iteration);
		}
		
		return max;
	}
	
	public static void main(String[] args) {
		int[] a = {4, 3, 2, 6};
		
		System.out.println("max: " + maxRotateFunction(a));
	}
}
